-- MathPad can plot an expression by using the "plot" command.
Xmin=-10; Xmax=10
plot 5*X
-- The independent variable "X" (upper case) is stepped between "Xmin" and "Xmax" with a resolution of "Xsteps" (default Xsteps=100). Various aspects of the plot can be controlled by special variables. None of the special variables are required but usually at least the range of X values is specified.
-- A info line at the bottom of the plot window shows the lowest and highest Y values ("Ylo" and "Yhi") calculated during the plot.
-- The variables "Ymin" and "Ymax" can be used to set the Y axis limits. If Ymin and/or Ymax are not specified MathPad will auto-range based on Ylo and Yhi.
-- Evaluation can be stopped by typing Command-period.
-- Multiple traces can be plotted simply by adding plot statements. All traces use the same values of "Xmin", "Xmax" , "Xsteps", "Ymin" and "Ymax". The "Ylo" and "Yhi" values apply over all traces.
f(t) = t^3/10 - 5*t
plot f(X)
plot f(2*X)/10
-- Clicking the mouse on the plot will show the trace number and the X,Y value of the plotted point nearest to the click.
-- A plot can be copied to the clipboard as a PICT. The "Copy Plot" menu items are enabled when the plot window is in front. The clipboard image will be the same size as the current plot window size. The "Copy Plot at 4X" command scales the image up to provide a higher resolution image for applications that can import and re-size PICTs.
-- A PICT can be pasted into the plot to provide a background. The PICT will be sized to fit inside the axis.
-- A plot can be printed. For printing, the plot is re-sized to the page regardless of the current plot window size. Printing is done at the highest printer resolution so it may be useful to increase Xsteps for a smoother plot. The Options... dialog controls whether the info line is included.
-- The Options... dialog allows adding grid lines. The color of the grid lines can be changed with ResEdit by changing 'ppat' resource 128.
-- Axis tics can be controlled by the special variables Xdiv and Ydiv. If these variables are used they override the automatic axis. They specify the distance between labeled tics in data units. The axis label format still assumes that "nice" divs (at most 2 digits of precision) will be used. This means that a div like .2 or .25 will work but a div of .234 will have rounded tic labels. If there are too many or too few divisions the axis will revert to automatic divisions.
Xdiv=2
-------- Adding labels
-- Arbitrary text labels may be pasted into the plot window. Selecting "Paste Label" from the Edit menu will paste text from clipboard into the upper left corner of the plot. Command-V will paste the label at the current mouse position if it is in the plot window.
-- "label" statements can be used to put a lines from the text window onto the plot. The text following "label" is evaluated normally. This allows labels that will automatically update when the text is re-evaluated.
label f(5):-12.500
-- Labels can be moved by dragging with the mouse.
-- Labels can be deleted by dragging them off the plot.
-- Special variables Xlabel, Ylabel and Title allow adding labels at preassigned locations. The plot size is adjusted to make room for these labels if they are present. These labels are not movable.
Title = "Test Plot"
Ylabel = "f(X)"
------- Multiple Plots
-- The "newaxis" command can be used to put more than one set of axes on a page. The plot control variables can be changed following a "newaxis". They must be changed with an := assignment. All changes to plot control variables must appear before the first plot statement for the new axis.
newaxis
Xmin:=-1:;
Ymin:=-1:; Ymax:=1:;
Ylabel:="arrays":
Xlabel:="X axis":
-- Any plot control variables that are not assigned will keep their previous values. A variable can be set back to undefined by assigning "?"
Xmax:=?:; -- enable auto-ranging
-- The special variable Ystrips can be used to preset the number of different axes that will be put on the plot. The use of Ystrips is optional. It can be used to prevent extra redrawing of the plot window.
Ystrips = 2
------- Plotting Arrays
-- The plot command can also plot points from 1D or 2D arrays.
-- For 1D {y1,y2,y3...} the element values are used for y. The points are plotted evenly spaced along the current X axis. The value of X is stepped from Xmin to Xmax and may be used if needed.
-- 2D arrays can be given in 3 forms:
-- array of x,y pairs {{x1,y1},{x2,y2},{x3,y3},...}
-- a pair of arrays {{x1,x2,...},{y1,y2,...}}
-- a pair of functions {fx(X),fy(X)}
-- a 2 by 2 array is treated as {{x1,x2},{y1,y2}}
-- For 2D arrays both x and y are taken from the array. X is stepped from 0 to 1.0 and can be used for parametric equations:
deg=X*360; Xsteps=36 -- run deg from 0 to 360 in 10° steps
x(angle)=cos(angle)
y(angle)=sin(angle)
plot {x(deg),y(deg)}
-- When plotting x,y points, if Xmin and/or Xmax are not specified they will be auto-ranged. When plotting a mix of arrays and functions, the array should be plotted first to take advantage of X auto-ranging.
-- The "plotline" command can be used to connect the points for any array plot. For {x,y} plots the points are connected in the order that they appear in the array. An undefined point causes the pen to be lifted. The pen is put down when the next defined point is found. If a single defined point is surrounded by undefineds it will not be plotted.
plotline {x(deg),y(deg)}*.7
-- 2D arrays representing surfaces can be displayed with the "image" command. Each array element is displayed as a tile filled with a color corresponding to its value. See the file "Images" for details.
Zmin=0; Zmax=30
array[ix,iy] = (ix-5)^2 + (iy-5)^2 dim[9,9]
image array
-------- Summary of special variables used for plotting
~
X independent variable
Xmin minimum value for X axis. minimum value of X unless 2D.
Xmax maximum value for X axis. maximum value of X unless 2D.